package com.qf.smsplatform.strategy.service.api;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Set;

/**
 * @Author: LeeRui
 * 2021/1/27 下午 10:19
 **/
//映射Cache服务的Controller
@FeignClient(value = "sms-platform-cache")
public interface CacheService {

    //根据key和field查询hash结构中的value
    @RequestMapping(value = "/cache/hget/{key}/{field}", method = RequestMethod.POST)
    public String hget(@PathVariable("key") String key, @PathVariable("field") String field);

    //使用sismember判断 member 元素是否是集合 key 的成员
    @RequestMapping(value = "/cache/sismember/{key}/{value}", method = RequestMethod.GET)
    public Boolean sismember(@PathVariable("key") String key,@PathVariable("value") String value);

    //使用zrangebyscore查询指定value中的范围数据
    @RequestMapping(value = "/cache/zrangebyscore/{key}/{min}/{max}", method = RequestMethod.GET)
    public Set<Object> zrangebyscore(@PathVariable("key") String key, @PathVariable("min") Long min, @PathVariable("max") Long max);

    //通过key获取String类型信息
    @RequestMapping(value = "/cache/get/{key}", method = RequestMethod.GET)
    public String get(@PathVariable("key") String key);

    //根据key查询key-set结构中value
    @RequestMapping(value = "/cache/smembers/{key}", method = RequestMethod.GET)
    public Set<String> smembers(@PathVariable("key") String key);

    //通过key和指定field将对应的value进行增加
    @RequestMapping(value = "/cache/hincr/{key}/{field}/{delta}", method = RequestMethod.POST)
    public Long hincr(@PathVariable("key") String key,@PathVariable("field") String field, @PathVariable("delta") long delta);

    //通过key将对应的value进行增加
    @RequestMapping(value = "/cache/incr", method = RequestMethod.GET)
    public Long incr(@RequestParam("key") String key, @RequestParam("delta") long delta);

}
